__author__ = '付鹏飞'
# -*- coding: UTF-8 -*-
import  requests
import json
import re
import day_03_download  #自定义模块引入
# from day_03_download import download #从day_03_download模块中引入一个download函数
# file_path = 'D:/python-workspace/file/download'

class Music(object):
    def __init__(self):
        self.api = 'https://music.taihe.com/v1/song/tracklink?appid=16073360&timestamp=1627205005'
        self.header = {
             'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36'
        }
        self.data = {
            'sign': '1d5c20497b016700b72e72728c65ef16',
            'TSID': 'T10044518998'
        }

    def get_page_content(self):
        response = requests.get(self.api,  headers=self.header, params=self.data)
        info = response.text
        info = re.findall(r'\"data\":(.*)\}', info)[0]
        return json.loads(info)

# def download(url, title):
#     response = requests.get(url)
#     with open("%s/%s.mp3" % (file_path, title), 'wb') as f:
#         f.write(response.content)

if __name__ == '__main__':
    music = Music()
    info = music.get_page_content()
    media_url = info['path']
    media_title = info['title']

    #download(media_url, media_title)
    day_03_download.download(media_url, media_title)

